/**
 * 上传简历
 */
import React from 'react';
import { Icon, Spin } from 'antd';
import UploadOss from '@/components/UploadOss';
import styles from './Record.less';

export default function DraggerResume({ previewUrl, onChange = () => {}, onPreviewChange = () => {} }) {
    const [uploading, setUploading] = React.useState(false);
    const [fileList, setFileList] = React.useState();
    const url = `https://view.officeapps.live.com/op/view.aspx?src=${previewUrl}`;

    return (
        <div className={styles.customDragger}>
            {!previewUrl && (
                <Spin spinning={uploading}>
                    <UploadOss
                        dragAble
                        uploadUrl="/api/resource/public/oss/v2/produceputpresignurls"
                        paramsOfUpload={{ richText: '1' }}
                        sysCode="OA"
                        categoryCode="originalResumeFile"
                        onUploaded={res => {
                            onPreviewChange(res[0].url);
                            setUploading(false);
                        }}
                        onChange={({ file = {} }) => {
                            if (file.status === 'uploading') {
                                setUploading(true);
                            }
                        }}
                        fileList={fileList}
                        setFileList={(_fileList, uploadResourceResult) => {
                            setFileList(_fileList);
                            onChange(uploadResourceResult);
                        }}
                        checkFileSize={10}
                        checkFileType="png、jpg、doc、docx、pdf、xlsx、xls"
                        checkFileTypeMsg="只能上传png、jpg、doc、docx、pdf、xlsx、xls格式的文件！"
                        checkFileSizeMsg="文件大小不能超过10MB！"
                        showUploadList={false}
                    >
                        <p className="ant-upload-drag-icon">
                            <Icon type="inbox" />
                        </p>
                        <p className="ant-upload-text">将简历拉至此处自动上传或浏览文件夹</p>
                        <p className="ant-upload-hint">支持pdf、doc、xls、docx、wps、html、txt等简历格式</p>
                    </UploadOss>
                </Spin>
            )}

            {previewUrl && (
                <iframe
                    title="简历预览"
                    style={{
                        width: '100%',
                        height: '600px',
                        border: 0
                    }}
                    src={url}
                />
            )}
        </div>
    );
}
